package main

import (
	"fmt"
	"sync"
	"time"
)

var (
	dict = make(map[int]int)
	lock sync.Mutex
)

func func1(id int) {
	sum := 0
	for i := 0; i < 10; i++ {
		sum += i
		lock.Lock()
		dict[i] = sum
		lock.Unlock()
	}

}

func main() {
	for i := 0; i < 4; i++ {
		go func1(i)
	}
	// 睡眠5秒
	time.Sleep(time.Second * 3)
	for k, v := range dict {
		fmt.Println("func1:", k, v)
	}
}
